/* header 登录转换 */
let uidn = localStorage.getItem('uid');
if (uidn != null) {
    let username = localStorage.getItem('username');
    $('#login').html(username).click(function(){
        var userRes = confirm('是否要退出登录');
        if(userRes == true){
            localStorage.removeItem('uid');
            localStorage.removeItem('username');
            location.href = './order.html';
        }
    })
}else{
    $('#login').html('登录').click(function(){
        location.href = './login.html'
    })
}


/* nav下拉跳转 */
$("#nav div ul").on('click', 'li', function () {
    localStorage.setItem('pclass', $(this).attr('pclass'));
    localStorage.setItem('pid', $(this).attr('pid'));
    location.href = './infor.html';
})
var html = '';
let username = localStorage.getItem('username');
let uid = localStorage.getItem('uid');
let num = localStorage.getItem('num');
let pri = localStorage.getItem('pri');
console.log(username,uid)
let orderList = JSON.parse(localStorage.getItem('orderList'));
console.log(orderList)
orderList.forEach(function (v) {
    console.log(v)
    html = `<li>
        <img src="${v.img}" alt="">
        <div>
            <h2>${v.title}</h2>
            <span>${v.price}</span>
            <br>
            <b>数量:${v.pnum}</b>
        </div>
    </li>`;
    html = $('#main ul').html() + html;
    $('#main ul').html(html);
})

$('#main div').find('#user').html(username);
$('#main div').find('#uid').html(username);
$('#main div').find('#num').html(num);
$('#main div').find('#pri').html(pri);


/* 点击事件 */
$('#main div #pay').click(function(){
    alert('暂未开放此功能，敬请期待')
})

$('#main div #cancel').click(function(){
    var res = confirm('是否要取消此订单!');
    if(res == true){
        localStorage.removeItem('num');
        localStorage.removeItem('pri');
        localStorage.removeItem('orderList');
        location.href = '../pages/carts.html'
    }
})
